import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

class Imp implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o1.compareTo(o2);
    }
}

public class Test {
    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        //时间复杂度 O(N)
        testHeap.createHeap();
        //时间复杂度 O(N*logN)
        testHeap.heapSort();
        System.out.println("===");
    }

    public static void main5(String[] args) {
        Solution solution = new Solution();
        int[] arr = {10,3,15,7,19,9};
        int[] ret = solution.smallestK(arr,3);
        System.out.println(Arrays.toString(ret));
    }

    public static void main4(String[] args) {
        Solution solution = new Solution();
        int[] arr = {10,3,15,7,19,9};
        int[] ret = solution.smallestK2(arr,3);
        System.out.println(Arrays.toString(ret));
    }

    public static void main3(String[] args) {
        Imp imp = new Imp();
        PriorityQueue priorityQueue = new PriorityQueue(imp);
        priorityQueue.offer(10);
        priorityQueue.offer(5);
        priorityQueue.offer(6);

        System.out.println(priorityQueue.poll());//5
        System.out.println(priorityQueue.poll());//6
    }

    public static void main2(String[] args) {
        //当实例化一个PriorityQueue对象之后，默认是一个小根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(10);
        priorityQueue.offer(5);
        priorityQueue.offer(6);

        System.out.println(priorityQueue.peek());//5
        System.out.println(priorityQueue.peek());//5

        System.out.println(priorityQueue.poll());//5
        System.out.println(priorityQueue.poll());//6

    }

    public static void main1(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        testHeap.createHeap();
        System.out.println(testHeap.pop());
        System.out.println("===");
    }
}
